//
//  VoiceMusicCell.m
//  SmileRead
//
//  Created by dllo on 15/8/25.
//  Copyright (c) 2015年 JIZ. All rights reserved.
//

#import "VoiceMusicCell.h"
#import "VoiceMusicModel.h"
#import "Path.h"

@interface VoiceMusicCell ()

@property (nonatomic, retain) UIImageView *musicImage;

@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UILabel *countLabel;
@property (nonatomic, retain) UIImageView *playImage;

@end


@implementation VoiceMusicCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.musicImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.musicImage];
        [_musicImage release];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        [_titleLabel release];
        
        self.countLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.countLabel];
        [_countLabel release];
        
        
        self.playImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.playImage];
        [_playImage release];
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.musicImage.frame = CGRectMake(10 * widthFit, 10 * heightFit, 80 * widthFit, 80 * heightFit);
    //self.musicImage.backgroundColor = [UIColor cyanColor];
    
    self.titleLabel.frame = CGRectMake(100 * widthFit, 10 * heightFit, self.frame.size.width - 140 * widthFit, 50 * heightFit);
    //self.titleLabel.backgroundColor = [UIColor grayColor];
    
    self.countLabel.frame = CGRectMake(100 * widthFit, 60 * heightFit, self.frame.size.width - 140 * widthFit, 30 * heightFit);
    //self.countLabel.backgroundColor = [UIColor greenColor];
 
    self.playImage.frame = CGRectMake(self.frame.size.width - 40 * widthFit, 40 * heightFit, 20 * widthFit, 20 * widthFit);
   // self.playImage.backgroundColor = [UIColor blackColor];
}

- (void)setModel:(VoiceMusicModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
        
        self.titleLabel.text = _model.title;
        
        if (_model.musicVisit != nil) {
            NSString *string  = [NSString stringWithFormat:@"🔊 %@", _model.musicVisit];
            self.countLabel.text = string;
        }
        else {
            self.countLabel.text = @"❤️";
        }
        
        self.countLabel.textColor = [UIColor blueColor];
        
        NSString *path = [Path pathOfImageWithName:@"music.png"];
        self.playImage.image = [UIImage imageWithContentsOfFile:path];
        [Path pathWithImageView:self.musicImage URLString:_model.coverimg];
    }
}


- (void)dealloc
{
    [_countLabel release];
    [_musicImage release];
    [_playImage release];
    [_titleLabel release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
